package com.gitee.wsl.struct.grammar

import com.gitee.wsl.struct.grammar.parser.combinator.check
import com.gitee.wsl.struct.grammar.parser.combinator.or
import com.gitee.wsl.struct.grammar.parser.combinator.validate
import com.gitee.wsl.struct.grammar.parser.token.regexToken
import com.gitee.wsl.struct.grammar.ast.node.ASTNode
import com.gitee.wsl.struct.grammar.ast.node.sample.lexeme
import com.gitee.wsl.struct.grammar.ext.parser
import com.gitee.wsl.transform.validator.strings.minlen
import kotlin.test.Test

class ValidatorTest {

    @Test
    fun regexTokenValidate() {
        object : Grammar<ASTNode>() {
            val data by regexToken("[ab]*", ignoreCase = true).validate { minlen(3){"mini 3"} }
            override val root by parser { lexeme(data) }
        }.run {
            println( parse("ababad") )
        }
    }

    @Test
    fun regexTokenCheck() {
        object : Grammar<ASTNode>() {
            val data by regexToken("[ab]*", ignoreCase = true).check { minlen(3){"mini 3"} }
            val data2 by regexToken("[ab]*", ignoreCase = true)
            override val root by parser { lexeme(data)  } or parser { lexeme(data2) }
        }.run {
            println( parse("ab") )
        }
    }
}